package com.zfl.thread.day01;

class BankThread extends Thread {
    private static int money=100;

    public BankThread(String name) {
        super(name);
    }

    @Override
    public void run() {
        for(int i=0;i<=10;i++) {
            if(i%2==0) {
                if(BankThread.money>=50) {
                    BankThread.money -= 50;
                    System.out.println(this.getName() + "取了50,余额[" + BankThread.money + "]元");
                } else {
                    System.out.println(this.getName()+"想要取50，余额只有["+BankThread.money+"]");
                }
            }else {
                BankThread.money+=50;
                System.out.println(this.getName()+"存了50，余额["+BankThread.money+"]元");
            }
        }
    }
}


public class Bankdemo03 {

    public static void main(String[] args) {
        new BankThread("用户1").start();
        new BankThread("用户2").start();
        new BankThread("用户3").start();
        new BankThread("用户4").start();
    }
}
